/*
 * @Author: wangdazhuang
 * @Date: 2024-10-16 21:29:25
 * @LastEditTime: 2024-10-29 21:52:37
 * @LastEditors: wangdazhuang
 * @Description: 
 * @FilePath: /pornhub_app/lib/src/views/mine/buy/views/mine_short_video_list.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/components/no_more/no_data.dart';
import 'package:pornhub_app/routes/routes.dart';
import 'package:pornhub_app/utils/extension.dart';
import 'package:pornhub_app/views/mine/buy/controllers/short_video_list_vc.dart';
import 'package:pornhub_app/views/douyin/short_video_list_cell.dart';

import '../../../../components/base_refresh/base_refresh_widget.dart';
import '../../../../components/no_more/no_data_masonry_grid_view.dart';

class MineShortVideoList extends StatefulWidget {
  final bool? isbuy;
  const MineShortVideoList({super.key, this.isbuy});

  @override
  State<StatefulWidget> createState() {
    return MineShortVideoListState();
  }
}

class MineShortVideoListState extends State<MineShortVideoList> {
  @override
  void initState() {
    Get.lazyPut(() => ShortVideoListVc(isbuy: widget.isbuy),
        tag: widget.isbuy == true ? "buy" : 'like');
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final iddd = widget.isbuy == true ? 'buy' : 'like';
    final controller = Get.find<ShortVideoListVc>(tag: iddd);
    return BaseRefreshWidget(
      controller,
      enableLoad: true,
      child: GetBuilder<ShortVideoListVc>(
        tag: iddd,
        id: iddd,
        builder: (_) {
          return NoDataMasonryGridView.count(
            crossAxisCount: 2,
            itemCount: _.videos.length,
            mainAxisSpacing: 8.w,
            crossAxisSpacing: 4.w,
            itemBuilder: (context, index) {
              final v = _.videos[index];
              final h = v.height! == 0 ? 273.w : v.height! / v.width! * 173.w;
              return ShortVideoListCell(
                width: 183.w,
                imageHeight: h,
                model: v,
              ).onTap(
                () {
                  Get.toShortVideoPlay(_.videos, idx: index);
                },
              );
            },
          ).marginOnly(left: 14.w, right: 14.w);
        },
      ),
    );
  }
}
